package com.xyc.student.mapper;

import com.xyc.student.pojo.Stu;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface StuMapper {
    @Select("select * from stu")
    List<Stu> find();

    @Select("select * from stu where id = #{id}")
    Stu findById(Integer id);

    @Update("update stu set name = #{name},cla = #{cla},s1 = #{s1},s2 = #{s2},s3 = #{s3},avg = ${avg},memo = #{memo} where id = #{id}")
    void update(Map<String, Object> map);

    @Select("select * from stu where id = #{id} ")
    Stu search(Integer id);

    @Insert("insert into stu(name,cla,s1,s2,s3,avg,memo) values (#{name},#{cla},#{s1},#{s2},#{s3},truncate((#{s1}+#{s2}+#{s3})/3,2),'123')")
    void insert(Map<String, Object> map);

    @Delete("delete from stu where id = #{id}")
    void del(Integer id);

    @Select("select * from stu limit #{from},#{to}")
    List<Stu> pageLimit(Map map);

    @Select("select count(*) from stu")
    Integer stuCount();

    @Select("select * from stu where name = #{name}")
    Stu findByName(String name);

}
